package com.simple.datax.seda.core;
import java.util.concurrent.LinkedBlockingQueue;
import com.simple.datax.seda.api.EnqueuePredicateIF;
import com.simple.datax.seda.api.QueueElementIF;
import com.simple.datax.seda.api.QueueIF;

public class UnboundedQueue implements QueueIF {

	public UnboundedQueue() {
		this.internalQueue = new LinkedBlockingQueue();
	}

	public boolean enqueue(QueueElementIF element) {
		synchronized (this.internalQueue) {
			try {
				this.internalQueue.put(element);
			} catch (InterruptedException e) {
				return false;
			}
		}
		return true;
	}

	public QueueElementIF dequeue() {
		synchronized (this.internalQueue) {
			return this.internalQueue.poll();
		}
	}

	private LinkedBlockingQueue<QueueElementIF> internalQueue = null;

	private EnqueuePredicateIF predicate = null;

	public EnqueuePredicateIF getPredicate() {
		return predicate;
	}

	public void setPredicate(EnqueuePredicateIF predicate) {
		this.predicate = predicate;
	}

}
